package com.tjc.deadlock;

import java.util.concurrent.locks.ReentrantLock;

/**
 * @Author: tjc
 * @description
 * @Date Created in 19:11 2022-09-21
 */
public class DeadLock {
    public static void main(String[] args) {
        ReentrantLock alock = new ReentrantLock();
        ReentrantLock block = new ReentrantLock();

        new Thread(()->{
            alock.lock();
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            block.lock();
            block.unlock();


            alock.lock();
        }).start();

        new Thread(()->{
            block.lock();
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            alock.lock();
            alock.unlock();


            block.lock();
        }).start();
    }
}
